#pragma once
#include<opencv2/opencv.hpp>
#include<iostream>
#include<vector>
using namespace std;
using namespace cv;


namespace tools {
    extern int g_threshold; // 全局阈值
    extern float TimeStep ; // 平滑后的每帧
    extern bool trackbar_created ;

    inline void draw_contours(Mat& image, const vector<Point>& points, const Scalar color = Scalar(255, 100, 255), int thickness = 2) {
        vector<vector<Point>> contours;
        contours.emplace_back(points);
        drawContours(image, contours, -1, color, thickness);
    }

    inline void draw_contours(Mat& image, const vector<Point2f>& points, const Scalar color = Scalar(0, 0, 255), int thickness = 2) {
        vector<Point>int_points(points.begin(), points.end());
        draw_contours(image, int_points, color, thickness);
    }
    inline void draw_text(Mat& image,const std::string &text,const cv::Point& point, double font_scale = 1.0,
        const cv::Scalar &color = cv::Scalar(0, 255, 255), int thickness = 2){
            cv::putText(image, text, point, cv::FONT_HERSHEY_SIMPLEX, font_scale, color, thickness);
    }

    inline void draw_armor(Mat& bgr_image,vector<Point>corners,Scalar color = (20,250,250),int thickness = 2){
        polylines(bgr_image,corners,true,color,thickness); 
        line(bgr_image,corners[0],corners[2],color,thickness);
        line(bgr_image,corners[1],corners[3],color,thickness);
    }
    
    // // 滑动条的参数配置
    // static void onTrackbar(int pos, void*) { // 改变函数
    //     g_threshold = pos;
    // }

    // // 滑动条
    // static void myframeBar(Mat &img){
    //     if (!trackbar_created) { // 只是创建一次
    //         cv::namedWindow("调节画面：", cv::WINDOW_NORMAL);
    //         cv::createTrackbar("阀值调节", "调节画面：", &tools::g_threshold, 255, tools::onTrackbar);
    //         trackbar_created = true;
    //     }
    //     cv::threshold(img, img, tools::g_threshold, 255, cv::THRESH_BINARY); // 这里是二值化
    //     cv::imshow("调节画面：", img);
    // }
    


    // // 获取Rect的中心点
    // Point getRectCenter(const Rect& rect) {
    //     int centerX = rect.x + rect.width / 2;
    //     int centerY = rect.y + rect.height / 2;
    //     return Point(centerX, centerY);
    // }

    // ***************************测试函数**************************************
    // void print_point(const Mat& image) {
    //     //int channels = image.channels();
    //     if (image.isContinuous()) {
    //         uchar* p = image.data;
    //         int image_col = image.cols;
    //         int channels =  image.channels();
    //         for (int i = 0; i < image.total(); i++) {
    //             int row = i / image.cols;
    //             int col = i % image.cols;
    //             if (channels == 1) {
    //             // 灰度图
    //             cout << "(" << row << "," << col << "): " << (int)*p << "\t";
    //             p += 1; // 移动1字节
    //             } else if (channels == 3) {
    //             // BGR彩色图
    //             cout << "(" << row << "," << col << "): B=" << (int)p[0] 
    //                  << ", G=" << (int)p[1] << ", R=" << (int)p[2] << "\t";
    //             p += 3; // 移动3字节
    //             }
    //             if ((i + 1) % image_col == 0)cout << endl;
    //         }
    //     }
    // }

    // // 验证旋转矩形的标注点位
    // void draw_rotated_rect(vector<Point2f> &rect,Mat &image) {        
    //     // 标点
    //     for(int i =0;i<4;i++){
    //         string point_name = "P"+to_string(i);
    //         putText(image, point_name, rect[i], FONT_HERSHEY_SIMPLEX, 0.5, Scalar(255,0,255), 1);
    //     }
    // }
    

}